﻿using System;

using Wicresoft.Framework.Organization;
using MaLu.BusiLogic;
using MaLu.Common;
using System.Data;
using MaLu.Data;
using MaLu.Framework.Common;
using System.Xml;
using System.Text;

namespace MaluJg.web.Move
{
    public partial class AddM : MovePage
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
          

            if (!IsPostBack)
            {
                if (MID != 0)
                {

                    DataTable dt = SqlHelper.Instance.ExecuteDataTable(Provider, "select * from Moving where id ='" + MID.ToString() + "'");
                    if (dt.Rows.Count > 0)
                    {
                        tbName.Text = dt.Rows[0]["EnterpriseName"].ToString();
                        tbYear.Text = dt.Rows[0]["Year"].ToString();
                    }
                }
            }
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("declare @id int; set @id={0}; select @id=id from Moving where id=@id;", MID);
            sb.AppendLine("if @@rowcount =0 begin");
            sb.AppendFormat(@"INSERT INTO [Moving]
           ([EnterpriseName],[Year])
     VALUES
           ({0},{1}); end else begin

UPDATE [Moving]
   SET [EnterpriseName] ={0},[Year] = {1}
 WHERE id=@id ; end", Util.ReturnSqlValue(tbName.Text), Util.ReturnSqlValue(tbYear.Text));

            SqlHelper.Instance.ExecuteNonQuery(Provider, sb.ToString());
            ClientScript.RegisterStartupScript(this.GetType(), "Close", "<script>alert('成功保存!');window.close();</script>");
        }
      
    }
}
